from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS, cross_origin

import config
from route.admin import admin
from route.book import book
from route.user import user
# from gevent import pywsgi

app = Flask(__name__)
cors = CORS(app)
app.config.from_object(config)  # 加载config.py配置文件
app.config['SECRET_KEY'] = '03e6f8g4'  # 一般借助os模块用环境变量

urls = [admin, book, user]  # 为各个路由注册
for url in urls:
    app.register_blueprint(url)


@app.route('/')
def index():  # put application's code here
    return render_template("index.html")


@app.route('/test')
def test():
    return {'code' : 200,
            'message' : '成功相应'}


# db = SQLAlchemy(app)

if __name__ == '__main__':
    # app.run(port="2000", host="127.0.0.1", debug=True)
    server = pywsgi.WSGIServer(('0.0.0.0', 8000), app)
    server.serve_forever()
